﻿using S7.Net;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace S7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Plc plc200smart;

        bool m00;
bool m01;

        bool m02;

        bool q00;



        private void button1_Click(object sender, EventArgs e)
        {

            if (label2.Text != "连接成功")
            {



                try
                {
                    plc200smart = new Plc(CpuType.S7200Smart, "192.168.1.15", 0, 1);
                    plc200smart.Open();
                    label1.Text = "连接成功";
                    timer1.Start();



                }

                catch (Exception)
                {


                    label2.Text = "连接失败";

                }


            }


            else
            { 
            
            plc200smart.Close();
                label2.Text = "断开连接";
                timer1.Stop();
            
            
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
          m00= (bool) plc200smart.Read("M0.0");
            q00 = (bool)plc200smart.Read("Q0.0");
            if (q00)
            {

                label10.Text = "true";

            }
            else
            {

                label10.Text = "false";

            }
            if (m00)

            {

                label7.Text = "true";


            }
            else
            {


                label7.Text = "false";

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            plc200smart.Write("Q0.0", 1);
          
        }

        private void button3_Click(object sender, EventArgs e)
        {
            plc200smart.Write("Q0.0", 0);
        }
    }
}
